<style type="text/css">
body,table,td,tr{
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:10px;
}

.level1{
	background-color:#BCBCBC;
}
.level2{
	background-color:#D1D1D1;
}
.level3{
	background-color:#E1E1E1;	
}
.level4{
	background-color:#F0F0F0;	
}
.level5{
	background-color:#FBFBFB;	
}

</style>

<form method="get" action="<?=$PHP_SELF?>">
<table border="1">
 <tr>
  <td>Cari Posisi:</td>
  <td><input type="text" name="keyword" /></td>
  <td><input type="submit" value="Go!" /></td>
 </tr>
</table>
</form>
<table width="100%" border="1">
<?
	include("lib/config.php");
	if(!empty($HTTP_GET_VARS['keyword'])){
		$sql = mssql_query("SELECT * FROM MstSO WHERE uraian LIKE '%".$HTTP_GET_VARS['keyword']."%'",$conn);
		while($row = mssql_fetch_array($sql)){
			echo"
			<tr>
			 <td><i>$row[uraian]</i> <br>
			 ";
			/* 
				catatan:
				direktorat			level 1		2 digit
				koordiantor			level 2		2 digit
				cabang/divisi/biro	level 3		3 digit
				bagian				level 4		3 digit
				seksi				level 5		2 digit
				
				000000000000
				123456789123 mssql
				012345678900 php
				
			*/
			$level1	= substr($row[kode_so],0,2); // direktorat
			$level2 = substr($row[kode_so],2,2); // koordinator
			$level3 = substr($row[kode_so],4,3); // cabang biro 
			$level4 = substr($row[kode_so],7,3); // bagian
			$level5 = substr($row[kode_so],10,2); //seksi
			
			// get direktorat
			$sql2 = mssql_query("select * from vleveldirektorat where substring(kode_so,1,2)='".$level1."' order by kode_so",$conn);
			if(mssql_num_rows($sql2) > 0){
			$row2 = mssql_fetch_array($sql2);
			echo"<b>Direktorat:</b> $row2[uraian] <br>";
			}
			// get koordinator teknis
			$sql3 = mssql_query("select * from vlevelkoordinator where substring(kode_so,1,4)='".$level1.$level2."' order by kode_so",$conn);
			if(mssql_num_rows($sql3) > 0){
			$row3 = mssql_fetch_array($sql3);
			echo"<b>Koor. Teknis:</b> $row3[uraian] <br>";
			}
			// get cabang/biro
			$sql4 = mssql_query("select * from vlevelcabang where substring(kode_so,1,7)='".$level1.$level2.$level3."' order by kode_so",$conn);
			if(mssql_num_rows($sql4) > 0){
			$row4 = mssql_fetch_array($sql4);
			echo"<b>Biro/Divisi/Unit Kerja/Cabang:</b> $row4[uraian] <br>";
			}
			// get bagian
			$sql5 = mssql_query("select * from vlevelbagian where substring(kode_so,1,10)='".$level1.$level2.$level3.$level4."' order by kode_so",$conn);
			if(mssql_num_rows($sql5) > 0){
			$row5 = mssql_fetch_array($sql5);
				echo"<b>Bagian:</b> $row5[uraian] <br>";
			}
			// get seksi
			$sql6 = mssql_query("select * from vlevelseksi where substring(kode_so,1,12)='".$level1.$level2.$level3.$level4.$level5."' order by kode_so",$conn);
			if(mssql_num_rows($sql6) > 0){
			$row6 = mssql_fetch_array($sql6);		
			echo"<b>Seksi:</b> $row6[uraian] <br>";				
			}
			// get lokasi
			$getlok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row[kode_lokasi]'",$conn);
			$rowlok	= mssql_fetch_array($getlok);
			echo"<b>Lokasi:</b> $rowlok[distrik], $rowlok[propinsi]";
			echo"</td></tr>
			";
		}
	}
	elseif($HTTP_GET_VARS['show'] == ''){
?>
 <tr>
  <td class="level1">NAMA DIREKTORAT</td>
  <td class="level1">LOKASI</td>
 </tr>
 <?
 	$sql = mssql_query("SELECT * FROM VLevelDirektorat",$conn);
	while($row = mssql_fetch_array($sql)){
 ?>
 <tr>
  <td>
  <?
  echo "<a href='$PHP_SELF?show=koordinator&amp;kode_so=$row[kode_so]'>".$row[uraian]."";
  ?>
  </td>
  <td>
  <?
  	// get lokasi
	$getlok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row[kode_lokasi]'",$conn);
	$rowlok	= mssql_fetch_array($getlok);
	echo"$rowlok[distrik], $rowlok[propinsi]";
  ?>
  </td>
 </tr>
 <?
 	}
	}
	elseif($HTTP_GET_VARS['show'] == "koordinator")
	{
	// get direktorat
	$sql = mssql_query("select * from vleveldirektorat where kode_so='".$HTTP_GET_VARS['kode_so']."'",$conn);
	$row = mssql_fetch_array($sql);
	echo"
	<tr>
	 <td width=40%><b>Direktorat: </b></td>
	 <td><a href='$PHP_SELF?show='>$row[uraian]</a></td>
	</tr>
	";
		$sql2 = mssql_query("select * from vlevelkoordinator where substring(kode_so,1,2)='".substr($HTTP_GET_VARS['kode_so'],0,2)."' order by kode_so",$conn);
		echo"
		 <tr> 
		  <td colspan=2><b>Koordinator Teknis:</b></td>
		 </tr>
		";
		while($row2 = mssql_fetch_array($sql2)){
			echo"
			<tr>
			 <td>&bull; <a href='$PHP_SELF?show=divisi&amp;level1=$row[kode_so]&amp;level2=$row2[kode_so]'>$row2[uraian]</a></td>
			 ";
			// get lokasi
			$getlok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row2[kode_lokasi]'",$conn);
			$rowlok	= mssql_fetch_array($getlok);
			echo"<td>$rowlok[distrik], $rowlok[propinsi]</td>";
			echo" 
			</tr>
			";
		}
	}
	// DIVISI
	elseif($HTTP_GET_VARS['show'] == "divisi")
	{
	// get direktorat
	$sql = mssql_query("select * from vleveldirektorat where kode_so='".$HTTP_GET_VARS['level1']."'",$conn);
	$row = mssql_fetch_array($sql);
	echo"
	<tr>
	 <td width=40%><b>Direktorat:</b> </td>
	 <td><a href='$PHP_SELF?show='>$row[uraian]</a> </td>
	</tr>
	";
		$sql2 = mssql_query("select * from vlevelkoordinator where kode_so='".$HTTP_GET_VARS['level2']."' order by kode_so",$conn);
		$row2 = mssql_fetch_array($sql2);
		echo"
		 <tr> 
		  <td><b>Koordinator Teknis: </b></td>
		  <td><a href='$PHP_SELF?show=koordinator&amp;kode_so=$row[kode_so]&amp;level2=$row2[kode_so]'>$row2[uraian]</a></td>
		 </tr>
		";
		// get cabang/divisi/unit/kerja
			$sql3 = mssql_query("select * from vlevelcabang where substring(kode_so,1,2)='".substr($HTTP_GET_VARS['level1'],0,2)."' and substring(kode_so,3,2)='".substr($HTTP_GET_VARS['level2'],2,2)."' order by kode_so",$conn);
			echo"
			 <tr> 
			  <td colspan=2><b>Divisi/Biro/Cabang/Unit Kerja:</b></td>
			 </tr>
			";
			while($row3 = mssql_fetch_array($sql3)){
				echo"
				<tr>
				 <td>&bull; <a href='$PHP_SELF?show=bagian&amp;level1=".$HTTP_GET_VARS['level1']."&amp;level2=$row2[kode_so]&amp;level3=$row3[kode_so]'>$row3[uraian]</a></td>";
			// get lokasi
			$getlok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row3[kode_lokasi]'",$conn);
			$rowlok	= mssql_fetch_array($getlok);
			echo"<td>$rowlok[distrik], $rowlok[propinsi]</td>";
			echo" 
			</tr>
			";
			}

	}
	
	// BAGIAN
	elseif($HTTP_GET_VARS['show'] == "bagian")
	{
	// get direktorat
	$sql = mssql_query("select * from vleveldirektorat where kode_so='".$HTTP_GET_VARS['level1']."'",$conn);
	$row = mssql_fetch_array($sql);
	echo"
	<tr>
	 <td width=40%><b>Direktorat:</b> </td>
	 <td><a href='$PHP_SELF?show='>$row[uraian]</a></td>
	</tr>
	";
		//$sql2 = mssql_query("select * from vlevelkoordinator where substring(kode_so,1,2)='".substr($HTTP_GET_VARS['level1'],0,2)."' order by kode_so",$conn);
		$sql2 = mssql_query("select * from vlevelkoordinator where kode_so='".$HTTP_GET_VARS['level2']."' order by kode_so",$conn);
		$row2 = mssql_fetch_array($sql2);
		echo"
		 <tr> 
		  <td><b>Koordinator Teknis:</b></td>
		  <td><a href='$PHP_SELF?show=koordinator&amp;kode_so=$row[kode_so]&amp;level2=$row2[kode_so]'>$row2[uraian]</a></td>
		 </tr>
		";
		// get cabang/divisi/unit/kerja
			$sql3 = mssql_query("select * from vlevelcabang where kode_so='".$HTTP_GET_VARS['level3']."'order by kode_so",$conn);
			$row3 = mssql_fetch_array($sql3);
			echo"
			 <tr> 
			  <td><b>Divisi/Biro/Cabang/Unit Kerja:</b></td>
			  <td><a href='$PHP_SELF?show=divisi&amp;level1=$row[kode_so]&amp;level2=$row2[kode_so]&amp;level3=$row3[kode_so]'>$row3[uraian]</a></td>
			 </tr>
			 <tr>
			  <td colspan=2><b>Bagian:</b> </td>
			 </tr>
			";
				$sql4 = mssql_query("select * from vlevelbagian where substring(kode_so,1,2)='".substr($HTTP_GET_VARS['level1'],0,2)."' and substring(kode_so,3,2)='".substr($HTTP_GET_VARS['level2'],2,2)."' and substring(kode_so,5,3)='".substr($HTTP_GET_VARS['level3'],4,3)."' order by kode_so",$conn);
				while($row4 = mssql_fetch_array($sql4)){
					echo"
					<tr>
					 <td>&bull; <a href='$PHP_SELF?show=seksi&amp;level1=$row[kode_so]&amp;level2=$row2[kode_so]&amp;level3=$row3[kode_so]&amp;level4=$row4[kode_so]'>$row4[uraian]</a></td>";
			// get lokasi
			$getlok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row4[kode_lokasi]'",$conn);
			$rowlok	= mssql_fetch_array($getlok);
			echo"<td>$rowlok[distrik], $rowlok[propinsi]</td>";
			echo" 
			</tr>
			";
				}
	}
	
	// SEKSI
	elseif($HTTP_GET_VARS['show'] == "seksi")
	{
	// get direktorat
	$sql = mssql_query("select * from vleveldirektorat where kode_so='".$HTTP_GET_VARS['level1']."'",$conn);
	$row = mssql_fetch_array($sql);
	echo"
	<tr>
	 <td width=40%><b>Direktorat:</b></td>
	 <td><a href='$PHP_SELF?show='>$row[uraian]</a></td>
	</tr>
	";
		$sql2 = mssql_query("select * from vlevelkoordinator where kode_so='".$HTTP_GET_VARS['level2']."' order by kode_so",$conn);
		$row2 = mssql_fetch_array($sql2);
		echo"
		 <tr> 
		  <td><b>Koordinator Teknis:</b></td>
		  <td><a href='$PHP_SELF?show=koordinator&amp;kode_so=$row[kode_so]&amp;level2=$row2[kode_so]'>$row2[uraian]</a></td>
		 </tr>
		";
		// get cabang/divisi/unit/kerja
			$sql3 = mssql_query("select * from vlevelcabang where kode_so='".$HTTP_GET_VARS['level3']."' order by kode_so",$conn);
			$row3 = mssql_fetch_array($sql3);
			$sql4 = mssql_query("select * from vlevelbagian where kode_so='".$HTTP_GET_VARS['level4']."' order by kode_so",$conn);
			$row4 = mssql_fetch_array($sql4);
			echo"
			 <tr> 
			  <td><b>Divisi/Biro/Cabang/Unit Kerja:</b> </td>
			  <td><a href='$PHP_SELF?show=divisi&amp;level1=$row[kode_so]&amp;level2=$row2[kode_so]&amp;level3=$row3[kode_so]'>$row3[uraian]</a></td>
			 </tr>
			 <tr>
			  <td><b>Bagian:</b></td>
			  <td><a href='$PHP_SELF?show=bagian&amp;level1=$row[kode_so]&amp;level2=$row2[kode_so]&amp;level3=$row3[kode_so]&amp;level4=$row4[kode_so]'>$row4[uraian]</td>
			 </tr>
			 <tr>
			  <td colspan=2><b>Seksi:</b></td>
			 </tr>			 
			";
				$sql5 = mssql_query("select * from vlevelseksi where substring(kode_so,1,2)='".substr($HTTP_GET_VARS['level1'],0,2)."' and substring(kode_so,3,2)='".substr($HTTP_GET_VARS['level2'],2,2)."' and substring(kode_so,5,3)='".substr($HTTP_GET_VARS['level3'],4,3)."' and substring(kode_so,8,3)='".substr($HTTP_GET_VARS['level4'],7,3)."' order by kode_so",$conn);
				while($row5 = mssql_fetch_array($sql5)){
					echo"
					<tr>
					 <td>&bull; $row5[uraian]</td>";
					// get lokasi
					$getlok = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row5[kode_lokasi]'",$conn);
					$rowlok	= mssql_fetch_array($getlok);
					echo"<td>$rowlok[distrik], $rowlok[propinsi]</td>";
					echo" 
					</tr>
					";
				}
	}
	
//	}
?>
</table>
